//
//  GCMAddReciveViewController.m
//  GeeCityManager
//
//  Created by 聚城科技 on 16/3/18.
//  Copyright © 2016年 聚城科技. All rights reserved.
//

#import "GCMAddReciveViewController.h"
#import "GCMAreaViewController.h"
#import "GCMSLRViewController.h"
#import "HJDatePickerView.h"
#import "GCMReciveViewController.h"
//图片相关的库的头文件
#import "AJPhotoPickerViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "AJPhotoBrowserViewController.h"


#define imgtag 100
#define IMAGE_WIDTH 80
#define spacing 5


@interface GCMAddReciveViewController ()<UIScrollViewDelegate,UIAlertViewDelegate,AJPhotoPickerProtocol,AJPhotoBrowserDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextViewDelegate>
/** NUmberViewController*/
@property(nonatomic, strong)    GCMNumberViewController *numberVC;
@property NSMutableArray *imageDatas;
/** 房间*/
@property(nonatomic, strong) UILabel *labelRoom;
/** 电话输入框*/
@property(nonatomic, strong)  UITextField *telTF;

@property (strong, nonatomic) UITextField *personTF;

@property (strong, nonatomic) UITextField *tousuTF;

@property(nonatomic, strong) UILabel *SLRLable;
//照片
@property (strong, nonatomic) NSMutableArray *photos;
@property (strong, nonatomic) NSMutableArray *ceamePhotos;
@property (strong, nonatomic) NSMutableArray *scPhotos;
@property (strong, nonatomic) NSMutableString *photoStr;

@end




@implementation GCMAddReciveViewController{
    NSString *labelRoomID ;
    NSMutableDictionary *_dataSource;
    UIScrollView *_scrollV;
    UIScrollView *_imageScrollV;
    UIView *_View1;
    UIView *_View2;
    UIView *_View3;
    UIView *_View4;
    UIView *_View5;
    UIButton *_roomBtn;
    UIButton *_SLRBtn;
    UIButton *_searchButton;
    UITextField *_tousuTF;
    UITextView *_miaoshuTF;
    UIButton *_jdlxBtn;
    UIButton *_khfyBtn1;
    UIButton *_khfyBtn2;
    UIButton *_yysjBtn1;
    UIButton *_yysjBtn2;
    UIButton *_imageBtn;
    UIButton *_subBtn;
    UIDatePicker * datePicker1;
    UIDatePicker * datePicker2;
    UIButton *_selectBtn;
    
    UITextField * currentTextfield;//当前的文本筐
    
    NSArray *_FYArray;
    NSArray *_FYArray1;
    NSMutableArray *_muenArr;
    NSMutableArray *_muenArr1;
    
}

-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = NO;
    //self.view1Datasource = [[NSMutableArray alloc]init];
    self.scPhotos = [[NSMutableArray alloc]init];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createScrollView];
    [self createImageScrollView];
    [self initData];
    [self downLoadData];
    //[self createUI];
    
    
}
-(void)createImageScrollView{
    //    创建可以滑动的视图
    _imageScrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(10, 590, SCREEN_WIDTH- 20, 100)];
    _imageScrollV.delegate = self;
    _imageScrollV.alwaysBounceHorizontal = NO;
    _imageScrollV.alwaysBounceVertical = NO;
    _imageScrollV.showsHorizontalScrollIndicator = NO;
    _imageScrollV.showsVerticalScrollIndicator = NO;
    _imageScrollV.bounces = NO;
    _imageScrollV.contentOffset = CGPointMake(0, 0);
    _imageScrollV.contentSize = CGSizeMake(SCREEN_WIDTH, 50);
    _imageScrollV.backgroundColor = [UIColor colorWithRed:.95 green:.95 blue:.95 alpha:1.0];
    self.automaticallyAdjustsScrollViewInsets = NO;
    _imageScrollV.userInteractionEnabled = YES;
    [_scrollV addSubview:_imageScrollV];
    
    
}

-(void)createScrollView{
    
    //    创建可以滑动的视图
    _scrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    _scrollV.delegate = self;
    _scrollV.alwaysBounceHorizontal = NO;
    _scrollV.alwaysBounceVertical = NO;
    _scrollV.showsHorizontalScrollIndicator = NO;
    _scrollV.showsVerticalScrollIndicator = NO;
    _scrollV.bounces = NO;
    _scrollV.contentOffset = CGPointMake(0, 0);
    _scrollV.contentSize = CGSizeMake(SCREEN_WIDTH, 820 );
    _scrollV.backgroundColor = [UIColor colorWithRed:.95 green:.95 blue:.95 alpha:1.0];
    self.automaticallyAdjustsScrollViewInsets = NO;
    _scrollV.userInteractionEnabled = YES;
    [self.view addSubview:_scrollV];
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapScrollerview)];
    tap.cancelsTouchesInView = NO;
    [_scrollV addGestureRecognizer:tap];
}
-(void)tapScrollerview{
    [self.view endEditing:YES];
}
-(void)downLoadData{
    
    [GCMReviceHttpRequst postFenLeiDataWithURL:RECEIVETYPE_URL Success:^(id obj, NSError *err) {
        //NSLog(@"s%@",obj);
        _FYArray1  = [[NSArray alloc]init];
        _FYArray1  = obj;
        
        [GCMReviceHttpRequst postFenLeiDataWithURL:RECEIVEREACTION_URL Success:^(id obj, NSError *err) {
            //NSLog(@"s%@",obj);
            _FYArray  = [[NSArray alloc]init];
            _FYArray  = obj;
            [self createUI];
        }];
        
    }];
   
}

-(void)createUI{
    
    self.view.backgroundColor = [UIColor colorWithRed:0.93 green:0.93 blue:0.93 alpha:1.00];
    //    View1
    _View1 = [[UIView alloc]initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH  - 20, 100)];
    _View1.backgroundColor = [UIColor whiteColor];
    _View1.layer.borderColor = [[UIColor redColor] CGColor];
    _View1.layer.borderWidth  = 1;
    _View1.layer.cornerRadius = 10;
    [_scrollV addSubview:_View1];
    
    UILabel *label1  = [[UILabel alloc]initWithFrame:CGRectMake(5, 50, SCREEN_WIDTH - 30, 1)];
    label1.layer.borderWidth = 1;
    label1.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    [_View1 addSubview:label1];
    
    _roomBtn  = [[UIButton alloc]initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH - 40, 40)];
    [_View1 addSubview:_roomBtn];
    _labelRoom  = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, _roomBtn.bounds.size.width , 40)];
    _labelRoom.text = @"  请选择房间 :";
    _labelRoom.textColor = [UIColor lightGrayColor];
    [_roomBtn addTarget:self action:@selector(roomButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_roomBtn addSubview:_labelRoom];
    UIImageView *imageView  = [[UIImageView alloc]initWithFrame:CGRectMake( _roomBtn.bounds.size.width - 40, 0, 40 , 40)];
    [imageView setImage:[UIImage imageNamed:@"common_ic_arrow_right.png"]];
    [_roomBtn addSubview:imageView];
    
    _personTF  = [[UITextField alloc]initWithFrame:CGRectMake(20, 55, (SCREEN_WIDTH - 40)/2, 40)];
    _personTF.placeholder = @"联系人：";
    _telTF  = [[UITextField alloc]initWithFrame:CGRectMake(20+ (SCREEN_WIDTH - 40)/2, 55 , (SCREEN_WIDTH - 40)/2, 40)];
    _telTF.placeholder = @"联系电话：";
    [_View1 addSubview:_personTF];
    [_View1 addSubview:_telTF];
    
    //    View2
    _View2 = [[UIView alloc]initWithFrame:CGRectMake(10, 120, SCREEN_WIDTH  - 20, 100)];
    _View2.backgroundColor = [UIColor whiteColor];
    _View2.layer.borderColor = [[UIColor redColor] CGColor];
    _View2.layer.borderWidth  = 1;
    _View2.layer.cornerRadius = 10;
    [_scrollV addSubview:_View2];
    
    UILabel *label2  = [[UILabel alloc]initWithFrame:CGRectMake(5, 50, SCREEN_WIDTH - 30, 1)];
    label2.layer.borderWidth = 1;
    label2.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    [_View2 addSubview:label2];
    
    _SLRBtn  = [[UIButton alloc]initWithFrame:CGRectMake(10, 55, SCREEN_WIDTH - 40, 40)];
    [_View2 addSubview:_SLRBtn];
    UILabel *labelSLR  = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, _SLRBtn.bounds.size.width/2 , 40)];
    labelSLR.text = @"请选择受理人(必填):";
    labelSLR.font = [UIFont systemFontOfSize:15];
    labelSLR.textAlignment = NSTextAlignmentCenter;
    [_SLRBtn addTarget:self action:@selector(onSLRBtClick) forControlEvents:UIControlEventTouchUpInside];
    labelSLR.textColor = [UIColor lightGrayColor];
    [_SLRBtn addSubview:labelSLR];
    _SLRLable  = [[UILabel alloc]initWithFrame:CGRectMake(labelSLR.bounds.size.width , 0, _SLRBtn.bounds.size.width  - labelSLR.bounds.size.width, 40)];
    _SLRLable.textAlignment = NSTextAlignmentCenter;
    [_SLRBtn addSubview:_SLRLable];
    UIImageView *imageView1  = [[UIImageView alloc]initWithFrame:CGRectMake( _SLRBtn.bounds.size.width - 40, 0, 40 , 40)];
    [imageView1 setImage:[UIImage imageNamed:@"common_ic_arrow_right.png"]];
    [_SLRBtn addSubview:imageView1];
    
    UIImageView *imageView3  = [[UIImageView alloc]initWithFrame:CGRectMake( _SLRBtn.bounds.size.width - 40, 0, 40 , 40)];
    [imageView3 setImage:[UIImage imageNamed:@"common_ic_arrow_right.png"]];
    
    _tousuTF  = [[UITextField alloc]initWithFrame:CGRectMake(20, 5, (SCREEN_WIDTH - 40), 40)];
    _tousuTF.placeholder = @"请填写投诉对象(必填)";
    [_View2 addSubview:_tousuTF];
    
    _searchButton  = [[UIButton alloc]initWithFrame:CGRectMake( _View2.bounds.size.width - 40, 15, 20 , 20)];
    [_searchButton setBackgroundImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
    [_searchButton addTarget:self action:@selector(onSearchTSDXBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_View2 addSubview:_searchButton];
    
    //    view3
    _View3 = [[UIView alloc]initWithFrame:CGRectMake(10, 230, SCREEN_WIDTH  - 20, 50)];
    _View3.backgroundColor = [UIColor whiteColor];
    //    _View3.layer.borderColor = [[UIColor redColor] CGColor];
    //    _View3.layer.borderWidth  = 1;
    _View3.layer.cornerRadius = 10;
    [_scrollV addSubview:_View3];
    
    UILabel *label3  = [[UILabel alloc]initWithFrame:CGRectMake(_View3.bounds.size.width/4, 5, 1, 40)];
    label3.layer.borderWidth = 1;
    label3.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    [_View3 addSubview:label3];
    UILabel *label4  = [[UILabel alloc]initWithFrame:CGRectMake(_View3.bounds.size.width/2, 5, 1, 40)];
    label4.layer.borderWidth = 1;
    label4.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    [_View3 addSubview:label4];
    
    UILabel *labelKHFY  = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, _View3.bounds.size.width/4 , 30)];
    labelKHFY.text = @"客户反应:";
    labelKHFY.textAlignment = NSTextAlignmentCenter;
    labelKHFY.font = [UIFont systemFontOfSize:15];
    labelKHFY.textColor  = [UIColor lightGrayColor];
    [_View3 addSubview:labelKHFY];
    
    _khfyBtn1  = [[UIButton alloc]initWithFrame:CGRectMake(_View3.bounds.size.width / 4 + 2, 5, _View3.bounds.size.width / 4  - 20, 40)];
    [_khfyBtn1 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [_khfyBtn1 setTitle:@"一般" forState:UIControlStateNormal];
    [_khfyBtn1 setBackgroundColor:[UIColor whiteColor]];
    [_khfyBtn1.layer setCornerRadius:0];
    [_khfyBtn1 addTarget:self action:@selector(onKHFYButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_khfyBtn1];
    NSMutableArray *fenleiA = [[NSMutableArray alloc]init];
    NSMutableArray *fenleib = [NSMutableArray arrayWithArray:_FYArray];
    //NSLog(@"%@",_FYArray);
    for (NSDictionary *dic in fenleib) {
        NSString *str =[ NSString stringWithFormat:@"%@", [dic valueForKey:@"name"] ];
        [fenleiA addObject:str];
        _muenArr = [NSMutableArray arrayWithArray:fenleiA];
    }
    [_khfyBtn1 setTitle:_muenArr[0] forState:UIControlStateNormal];
    [_View3 addSubview:_khfyBtn1];
    //    UILabel *labelkhfy1  = [[UILabel alloc]initWithFrame:CGRectMake(0, 5, _khfyBtn1.bounds.size.width/3*2  , 30)];
    //    labelkhfy1.text = @"一般";
    //    labelkhfy1.textColor = [UIColor lightGrayColor];
    //    [_khfyBtn1 addSubview:labelkhfy1];
    UIImageView *imageView5  = [[UIImageView alloc]initWithFrame:CGRectMake( _khfyBtn1.bounds.size.width - 5 , 10, 20 , 20)];
    [imageView5 setImage:[UIImage imageNamed:@"xiala"]];
    [_khfyBtn1 addSubview:imageView5];
    
    _khfyBtn2  = [[UIButton alloc]initWithFrame:CGRectMake(_View3.bounds.size.width / 2 + 10, 5, _View3.bounds.size.width / 2  - 20, 40)];
    [_View3 addSubview:_khfyBtn2];
    UILabel *labelkhfy2  = [[UILabel alloc]initWithFrame:CGRectMake(30, 10, _khfyBtn2.bounds.size.width - 20  , 20)];
    labelkhfy2.text = @"二次及以上投诉";
    labelkhfy2.font = [UIFont systemFontOfSize:15];
    labelkhfy2.textColor = [UIColor redColor];
    [_khfyBtn2 addSubview:labelkhfy2];
    UILabel *klabel = [[UILabel alloc]initWithFrame:CGRectMake( 0 , 10, 20 , 20)];
    klabel.layer.borderColor = [[UIColor lightGrayColor]CGColor];
    klabel.layer.borderWidth = 1;
    [_khfyBtn2 addSubview:klabel];
    
     _selectBtn = [[UIButton alloc]initWithFrame:CGRectMake( 0 , 10, 20 , 20)];
    [_selectBtn setImage:[UIImage imageNamed:@"task_btn_submit"] forState:UIControlStateNormal];
    [_selectBtn setImage:[UIImage imageNamed:@"select"] forState:UIControlStateSelected];
    [_selectBtn addTarget:self action:@selector(seleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [_khfyBtn2 addSubview:_selectBtn];
    
    //    view4
    _View4 = [[UIView alloc]initWithFrame:CGRectMake(10, 290, SCREEN_WIDTH  - 20, 50)];
    [_scrollV addSubview:_View4];
    
    UILabel *label5  = [[UILabel alloc]initWithFrame:CGRectMake(_View4.bounds.size.width/4 *3 - 10, 5, 1, 40)];
    label5.layer.borderWidth = 1;
    label5.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    [_View4 addSubview:label5];
    
    UILabel *labelYYSJ  = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, _View4.bounds.size.width/3 , 30)];
    labelYYSJ.text = @"客户预约时间:";
    labelYYSJ.textAlignment = NSTextAlignmentCenter;
    labelYYSJ.font = [UIFont systemFontOfSize:15];
    labelYYSJ.textColor  = [UIColor lightGrayColor];
    [_View4 addSubview:labelYYSJ];
    
    _yysjBtn1 = [[UIButton alloc]initWithFrame:CGRectMake(_View4.bounds.size.width / 3  - 10, 5, _View4.bounds.size.width / 4 *3 - _View4.bounds.size.width / 3 - 10, 40)];
    UIImageView *tiemimageV1 = [[UIImageView alloc]initWithFrame:CGRectMake( _yysjBtn1.bounds.size.width - 10, 13, 13, 13 )];
    tiemimageV1.image = [UIImage imageNamed:@"date_tab"];
    _yysjBtn1.titleLabel.font = [UIFont systemFontOfSize:15];
    [_yysjBtn1 addSubview:tiemimageV1];
    //_yysjBtn1.backgroundColor = [UIColor redColor];
    NSString *timestr = [NSString stringWithFormat:@"%@",[NSDate date]];
    NSLog(@"%@",timestr);
    //[_yysjBtn1 setTitle:timestr forState:UIControlStateNormal];
    NSArray *arrayt1 = [timestr componentsSeparatedByString:@" "];
    [_yysjBtn1 setTitle:arrayt1[0] forState:UIControlStateNormal];
    [_yysjBtn1 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [_yysjBtn1 addTarget: self action:@selector(onyyshBtn1Click) forControlEvents:UIControlEventTouchUpInside];
    [_View4 addSubview:_yysjBtn1];
    
    _yysjBtn2 = [[UIButton alloc]initWithFrame:CGRectMake(_View4.bounds.size.width / 4 *3 - 10 , 5 , _View4.bounds.size.width / 4 , 40)];
    _yysjBtn2.titleLabel.font = [UIFont systemFontOfSize:15];
    UIImageView *tiemimageV2 = [[UIImageView alloc]initWithFrame:CGRectMake( _yysjBtn2.bounds.size.width  - 5, 13, 13, 13 )];
    tiemimageV2.image = [UIImage imageNamed:@"date_tab"];
    [_yysjBtn2 addSubview:tiemimageV2];
    //_yysjBtn2.backgroundColor = [UIColor blueColor];
    [_yysjBtn2 setTitle:arrayt1[1] forState:UIControlStateNormal];
    [_yysjBtn2 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [_yysjBtn2 addTarget: self action:@selector(onyyshBtn2Click) forControlEvents:UIControlEventTouchUpInside];
    [_View4 addSubview:_yysjBtn2];
    
    //   view5
    _View5 = [[UIView alloc]initWithFrame:CGRectMake(10, 350, SCREEN_WIDTH  - 20, 150)];
    _View5.backgroundColor = [UIColor whiteColor];
    _View5.layer.borderColor = [[UIColor redColor] CGColor];
    _View5.layer.borderWidth  = 1;
    _View5.layer.cornerRadius = 10;
    [_scrollV addSubview:_View5];
    
    UILabel *label6  = [[UILabel alloc]initWithFrame:CGRectMake(5, 100, SCREEN_WIDTH - 30, 1)];
    label6.layer.borderWidth = 1;
    label6.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    [_View5 addSubview:label6];
    UILabel *label7  = [[UILabel alloc]initWithFrame:CGRectMake(_View5.bounds.size.width/3, 110, 1, 30)];
    label7.layer.borderWidth = 1;
    label7.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    [_View5 addSubview:label7];
    
    _jdlxBtn  = [[UIButton alloc]initWithFrame:CGRectMake(_View5.bounds.size.width/3, 110, _View5.bounds.size.width/3 *2, 40)];
    [_jdlxBtn addTarget:self action:@selector(onJFLXButtonClick) forControlEvents:UIControlEventTouchUpInside];
    NSMutableArray *fenleiA1 = [[NSMutableArray alloc]init];
    NSMutableArray *fenleib1 = [NSMutableArray arrayWithArray:_FYArray1];
    //NSLog(@"asdfasdf%@",_FYArray1);
    for (NSDictionary *dic in fenleib1) {
        NSString *str =[ NSString stringWithFormat:@"%@", [dic valueForKey:@"name"] ];
        [fenleiA1 addObject:str];
        _muenArr1 = [NSMutableArray arrayWithArray:fenleiA1];
    }
    NSLog(@"%@",_FYArray1);
    [_jdlxBtn setTitle:_muenArr1[0] forState:UIControlStateNormal];
    [_jdlxBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];

    [_View5 addSubview:_jdlxBtn];
    
    UILabel * labJD =[[UILabel alloc]initWithFrame:CGRectMake(5, 110, _View5.bounds.size.width / 3, 30)];
    labJD.text = @"  接待类型  :";
    labJD.textColor = [UIColor lightGrayColor];
    [_View5 addSubview:labJD];
    
    _miaoshuTF  = [[UITextView alloc]initWithFrame:CGRectMake(10, 10, (SCREEN_WIDTH - 40), 80)];
    _miaoshuTF.tag = 1230;
    _miaoshuTF.font = [UIFont systemFontOfSize:14]; //注意先设置字体,再设置placeholder
    _miaoshuTF.placeholder = @"请填写接待描述";
    [_View5 addSubview:_miaoshuTF];
    
    
    //    获取图片
    UIButton *button = [[UIButton alloc]init];
    button.frame = CGRectMake(SCREEN_WIDTH / 2 - 30, 510, 60, 60) ;
    [button setImage:[UIImage imageNamed:@"btn_app_pic"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(imageGet) forControlEvents:UIControlEventTouchUpInside];
    [_scrollV addSubview:button];
    
    //NSLog(@"%@",self.view1Datasource);
    
    //    提交按钮
    _subBtn  = [[UIButton alloc]initWithFrame:CGRectMake(30, 720, SCREEN_WIDTH - 60, 50)];
    [_subBtn addTarget:self action:@selector(onSubmitClick) forControlEvents:UIControlEventTouchUpInside];
    [_subBtn setTitle:@"提交" forState:UIControlStateNormal];
    _subBtn.backgroundColor = [UIColor colorWithRed:0 green:0.67 blue:0.65 alpha:1.00];
    [_scrollV addSubview:_subBtn];
    
}

-(void)onSubmitClick{
    
    if ([_labelRoom.text isEqualToString:@"  请选择房间 :"]) {
        
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"请选择房间" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
    
    }else if ([_personTF.text isEqualToString:@"联系人："]||[_personTF.text isEqualToString:@""]){
    
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"请填写联系人" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
        
    }else if ([_telTF.text isEqualToString:@"联系电话："]||[_telTF.text isEqualToString:@""]){
        
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"请填写联系电话" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
        
    }else if ([_tousuTF.text isEqualToString:@"请填写投诉对象(必填)"]||[_tousuTF.text isEqualToString:@""]){
        
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"请填写投诉对象" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
        
    }else if ([_SLRBtn.titleLabel.text isEqualToString:@""]){
        
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"请填写受理人" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
        
    }else if ([_miaoshuTF.text isEqualToString:@"请填写你的接待描述"]||[_miaoshuTF.text isEqualToString:@""]){
        
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"请填写你的接待描述" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
        
    }else{
    
        [self Submit];
    }
    
    
    
//    parameters[@"userName"] = @"客户经理";
//    NSArray *roomarray = [[NSArray alloc]init];
//    roomarray  = [labelRoomID componentsSeparatedByString:@"-"];
//    //   NSLog(@"%@",roomarray);
//    parameters[@"courtId"] = @"1";
//    parameters[@"buildingId"] = @"1";
//    parameters[@"unitId"] = @"1";
//    parameters[@"roomId"] = @"101";
//    parameters[@"roomName"] = @"迪生山庄-1号楼-1-101";
//    parameters[@"contact"] = @"赵学智";
//    parameters[@"tel"] = @"13573882999";
//    NSArray *comarray = [[NSArray alloc]init];
//    comarray  = [labelRoomID componentsSeparatedByString:@"-"];
//    parameters[@"complintCourtId"] = @"1";
//    parameters[@"complintBuildingId"] = @"1";
//    parameters[@"complintUnitId"] = @"1";
//    parameters[@"complintRoomId"] = @"102";
//    parameters[@"complintRoomName"] = @"迪生山庄-1号楼-1-109";
//    parameters[@"reaction"] = @"16";
//    parameters[@"twos"] = @"0";
//    parameters[@"time"] = @"2016-04-01 10:22:24";
//    parameters[@"content"] = @"赵学智";
//    parameters[@"type"] = @"18";
//    parameters[@"images"] = @"";
//    parameters[@"followname"] = @"项目经理";

    
}

-(void)Submit{

    NSMutableDictionary *parameters = [[NSMutableDictionary alloc]init];
    parameters[@"userName"] = [GCMUserInfo instance].realName;
    NSArray *roomarray = [[NSArray alloc]init];
    roomarray  = [labelRoomID componentsSeparatedByString:@"-"];
 //   NSLog(@"%@",roomarray);
    parameters[@"courtId"] = roomarray[0];
    parameters[@"buildingId"] = roomarray[1];
    parameters[@"unitId"] = roomarray[2];
    parameters[@"roomId"] = roomarray[3];
    parameters[@"roomName"] = _labelRoom.text; 
    parameters[@"contact"] = _personTF.text;
    parameters[@"tel"] = _telTF.text;
    NSArray *comarray = [[NSArray alloc]init];
    comarray  = [labelRoomID componentsSeparatedByString:@"-"];
    parameters[@"complintCourtId"] = comarray[0];
    parameters[@"complintBuildingId"] = comarray[1];
    parameters[@"complintUnitId"] = comarray[2];
    parameters[@"complintRoomId"] = comarray[3];
    parameters[@"complintRoomName"] = _tousuTF.text;
//    parameters[@"reaction"] = @"16";
    
    for (NSDictionary *dic  in _FYArray) {
        if ([_khfyBtn1.titleLabel.text isEqualToString:[dic valueForKey:@"name"]]) {
            parameters[@"reaction"] = [dic valueForKey:@"id"];
        }
    }
    if (_khfyBtn2.isSelected == NO) {
         parameters[@"twos"] = @"0";
    }else{
         parameters[@"twos"] = @"1";
    }
    parameters[@"twos"] = @"0";
    parameters[@"time"] = [NSString stringWithFormat:@"%@ %@",_yysjBtn1.titleLabel.text,_yysjBtn2.titleLabel.text];
    parameters[@"content"] = _miaoshuTF.text;
    for (NSDictionary *dic  in _FYArray1) {
        if ([_jdlxBtn.titleLabel.text isEqualToString:[dic valueForKey:@"name"]]) {
            parameters[@"type"] = [dic valueForKey:@"id"];
        }
    }
    for (UIImageView *imageV in _imageScrollV.subviews) {
        NSData *data = UIImageJPEGRepresentation(imageV.image, 0.4);
        NSString* encodeResult = [data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
        if (encodeResult) {
            [self.scPhotos addObject:encodeResult];
            //NSLog(@"ppppppic%@",self.photos);
        }else{
            // [self.photos addObject:data];
        }

        //NSLog(@"%@",self.scPhotos);
    }
    NSString * substr = [self.scPhotos componentsJoinedByString:@","];
    //NSLog(@"%ld",self.scPhotos.count);
    parameters[@"images"] = substr;
    parameters[@"followname"] = _SLRLable.text;
    NSLog(@"测试数据%@",parameters);
    [GCMTaskHttpRequst postDataWithParmerts:parameters WithUrl:RECEIVEADD_URL Success:^(id obj, NSError *err) {
        //NSLog(@"测试成功了%@",obj);
        // NSLog(@"测试成功了");
    }];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)seleButtonClick:(UIButton *)button {
    button.selected = !button.selected;
}

//选择房间按钮
-(void)roomButtonClick{
    self.numberVC = [[GCMNumberViewController alloc]init];
    __weak typeof(self) WeakSelf = self;
    self.numberVC.getMessageBlock = ^(NSMutableArray *dataSource){
        NSLog(@"---------%@",dataSource);
        WeakSelf.labelRoom.text = [dataSource valueForKey:@"add"];
        labelRoomID = [dataSource valueForKey:@"idd"];
        WeakSelf.personTF.text = [[ dataSource valueForKey:@"data" ] valueForKey:@"name"];
        WeakSelf.telTF.text = [[ dataSource valueForKey:@"data" ] valueForKey:@"tel"];
        WeakSelf.tousuTF.text = [dataSource valueForKey:@"add"];
        WeakSelf.SLRLable.text = [[ dataSource valueForKey:@"data" ] valueForKey:@"bankName"];
    };
    GCMAreaViewController *main =[[GCMAreaViewController alloc]init];
    main.numberVC = self.numberVC;
    [self.navigationController pushViewController:main animated:YES];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"小区选择";
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.backBarButtonItem = backItem;
}

//选择投诉对象
-(void)onSearchTSDXBtnClick{
    self.numberVC = [[GCMNumberViewController alloc]init];
    __weak typeof(self) WeakSelf = self;
    self.numberVC.getMessageBlock = ^(NSMutableArray *dataSource){
        NSLog(@"---------%@",dataSource);
        WeakSelf.tousuTF.text = [dataSource valueForKey:@"add"];
    };
    GCMAreaViewController *main =[[GCMAreaViewController alloc]init];
    main.numberVC = self.numberVC;
    [self.navigationController pushViewController:main animated:YES];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"小区选择";
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.backBarButtonItem = backItem;
    
}

-(void)onSLRBtClick{
    GCMSLRViewController *main =[[GCMSLRViewController alloc]init];

    //3.设置回调的block
    main.returnStrBlock = ^(NSString * str){
        _SLRLable.text = str;
        
        _SLRLable.textColor = [UIColor lightGrayColor];
    };
    [self.navigationController pushViewController:main animated:YES];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"成员选择";
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.backBarButtonItem = backItem;
}





//获取时间1
-(void)onyyshBtn1Click{
    
    HJDatePickerView * datePickerView = [[HJDatePickerView alloc]init];
    [datePickerView createDatePickerMode:UIDatePickerModeDate GetTime:^(NSString *time) {
        NSString *nstring = time;
        NSArray *array = [nstring componentsSeparatedByString:@" "];
        [_yysjBtn1 setTitle:array[0] forState:UIControlStateNormal];
    }];
//    UIWindow * window = [UIApplication sharedApplication].keyWindow;
//    [window addSubview:datePickerView];
//    
//    [datePickerView setGetTimeBlock:^(NSString *time){
//        
//        NSString *nstring = time;
//        NSArray *array = [nstring componentsSeparatedByString:@" "];
//        [_yysjBtn1 setTitle:array[0] forState:UIControlStateNormal];
//    }];
    
}
//获取时间2
-(void)onyyshBtn2Click{
    
    HJDatePickerView * datePickerView = [[HJDatePickerView alloc]init];
    [datePickerView createDatePickerMode:UIDatePickerModeTime GetTime:^(NSString *time) {
        NSString *nstring = time;
        NSArray *array = [nstring componentsSeparatedByString:@" "];
        [_yysjBtn2 setTitle:array[1] forState:UIControlStateNormal];
    }];
//    UIWindow * window = [UIApplication sharedApplication].keyWindow;
//    [window addSubview:datePickerView];
//    
//    [datePickerView setGetTimeBlock:^(NSString *time){
//        
//        NSString *nstring = time;
//        NSArray *array = [nstring componentsSeparatedByString:@" "];
//        [_yysjBtn2 setTitle:array[1] forState:UIControlStateNormal];
//    }];
    
}

-(void)initData{
    
    _dataSource = [[NSMutableDictionary alloc]init];
    _muenArr  = [[NSMutableArray alloc]init];
    _muenArr1  = [[NSMutableArray alloc]init];
    self.ceamePhotos = [[NSMutableArray alloc]init];
}


////////////添加下拉MENU///////////////////
-(void)onJFLXButtonClick{

    __weak typeof(self)weakSelf=self;
    if (!_jdlxmuen) {
        
        _jdlxmuen=[[SCXCreateAlertView2 alloc]initWithNameArray:_muenArr1 andMenuOrigin:CGPointMake((SCREEN_WIDTH - 20)/2 - 40,_View5.frame.origin.y + 150) andMenuWidth:(SCREEN_WIDTH - 20)/2 andHeight:40 andLayer:0 andTableViewBackGroundColor:[UIColor clearColor] andIsSharp:YES andType:kNavigationPop2];
        _jdlxmuen.delegate = weakSelf;
        _jdlxmuen.tableViewDelegate=self;
        _jdlxmuen.dismiss=^(){
            [weakSelf.jdlxmuen removeFromSuperview];
            _jdlxmuen=nil;
        };
        [_scrollV addSubview:_jdlxmuen];
    }
    else{
        [_jdlxmuen dismissWithCompletion:^(SCXCreateAlertView2 *create){
            [_jdlxmuen removeFromSuperview];
            _jdlxmuen = nil;
        }];
    }

    
}


#pragma mark--展示下拉菜单
-(void)onKHFYButton{
    
    __weak typeof(self)weakSelf=self;
    if (!_kufymuen) {
        
        _kufymuen=[[SCXCreateAlertView alloc]initWithNameArray:_muenArr andMenuOrigin:CGPointMake((SCREEN_WIDTH - 20)/4 + 10,_View3.frame.origin.y + 50) andMenuWidth:(SCREEN_WIDTH - 20)/4 andHeight:40 andLayer:0 andTableViewBackGroundColor:[UIColor clearColor] andIsSharp:YES andType:kNavigationPop];
        _kufymuen.delegate = weakSelf;
        _kufymuen.tableViewDelegate=self;
        _kufymuen.dismiss=^(){
            [weakSelf.kufymuen removeFromSuperview];
            _kufymuen=nil;
        };
        [_scrollV addSubview:_kufymuen];
    }
    else{
        [_kufymuen dismissWithCompletion:^(SCXCreateAlertView *create){
            [_kufymuen removeFromSuperview];
            _kufymuen = nil;
        }];
    }
}
#pragma mark--自定义下拉菜单代理方法,点击下拉菜单某一行时候对应的响应时间，点击完成后试图要消失，用一个block通知；
-(void)tableViewDidSelectRowAtIndexPath:(NSIndexPath *)indexPath andPopType:(popType)popViewType{
    
    //改变导航栏文字
    if (popViewType == kNavigationPop) {
        [_khfyBtn1 setTitle:_muenArr[indexPath.row] forState:UIControlStateNormal];
    }
    [_kufymuen dismissWithCompletion:nil];//点击完成后视图消失;
    
    //    [GCMReviceHttpRequst postReciveListDataWithcourtId:[GCMUserInfo instance].areaId Withremark:@"1" WithPage:@"1" WithUserName:[GCMUserInfo instance].realName Success:^(id obj, NSError *err) {
    //        NSLog(@"+++%@",obj);
    //        _dataSource = obj;
    //        [_tableV reloadData];
    //    }];
    
}


-(void)secondtableViewDidSelectRowAtIndexPath:(NSIndexPath *)indexPath andPopType:(popType2)popViewType{
    
    //改变导航栏文字
    if (popViewType==kNavigationPop2) {
        [_jdlxBtn setTitle:_muenArr1[indexPath.row] forState:UIControlStateNormal];
    }
    
    //    NSLog(@"%@%@",_yearArr1[indexPath.row],_monthArr1[indexPath.row]);
    //
    //    [GCMReviceHttpRequst postReciveListDataWithcourtId:_yearArr1[indexPath.row] Withremark:_monthArr1[indexPath.row] WithPage:@"1" WithUserName:[GCMUserInfo instance].realName Success:^(id obj, NSError *err) {
    //        NSLog(@"+++%@",obj);
    //        _dataSource = obj;
    //        [_tableV reloadData];
    //    }];
    
    
    
    
    [_jdlxmuen dismissWithCompletion:nil];//点击完成后视图消失;
}



////////////////////////////获取图片//////////////////////////////////////
-(void)imageGet{
    
    AJPhotoPickerViewController *picker = [[AJPhotoPickerViewController alloc] init];
    picker.maximumNumberOfSelection = 15;
    picker.multipleSelection = YES;
    picker.assetsFilter = [ALAssetsFilter allPhotos];
    picker.showEmptyGroups = YES;
    picker.delegate=self;
    picker.selectionFilter = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
        return YES;
    }];
    [self presentViewController:picker animated:YES completion:nil];
    //NSLog(@"ppppppic%@",self.photos);
}
#pragma mark - BoPhotoPickerProtocol
- (void)photoPickerDidCancel:(AJPhotoPickerViewController *)picker {
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)photoPicker:(AJPhotoPickerViewController *)picker didSelectAssets:(NSArray *)assets {
    [self.photos addObjectsFromArray:assets];
    CGFloat x = 0;
    CGRect frame = CGRectMake(0, 0, 100, 100);
    if (self.ceamePhotos.count == 0) {
        for (int i = 0 ; i < self.photos.count; i++) {
            ALAsset *asset = self.photos[i];
            UIImage *tempImg = [UIImage imageWithCGImage:asset.defaultRepresentation.fullScreenImage];
            frame.origin.x = x;
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            imageView.clipsToBounds = YES;
            imageView.image = tempImg;
            imageView.tag = i;
            imageView.userInteractionEnabled = YES;
            [imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showBig:)]];
            [_imageScrollV addSubview:imageView];
            x += frame.size.width+5;
        }

    } else {
        //[self.photos addObjectsFromArray:self.ceamePhotos];
        for (int i = 0 ; i < self.photos.count; i++) {
            frame.origin.x = 105 *self.ceamePhotos.count + x;
            ALAsset *asset = self.photos[i];
            UIImage *tempImg = [UIImage imageWithCGImage:asset.defaultRepresentation.fullScreenImage];
            UIImageView *imageVie = [[UIImageView alloc] initWithFrame:frame];
            [imageVie setContentMode:UIViewContentModeScaleAspectFill];
            imageVie.clipsToBounds = YES;
            imageVie.image = tempImg;
            imageVie.userInteractionEnabled = YES;
            [imageVie addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showBig:)]];
            [_imageScrollV addSubview:imageVie];
            x += frame.size.width+5;
        }
    }
           _imageScrollV.contentSize = CGSizeMake(105 * (self.photos.count +self.ceamePhotos.count) - 5, 0);
    [picker dismissViewControllerAnimated:NO completion:nil];
    
}

- (void)photoPicker:(AJPhotoPickerViewController *)picker didSelectAsset:(ALAsset *)asset {
    NSLog(@"%s",__func__);
}

- (void)photoPicker:(AJPhotoPickerViewController *)picker didDeselectAsset:(ALAsset *)asset {
    NSLog(@"%s",__func__);
}

//超过最大选择项时
- (void)photoPickerDidMaximum:(AJPhotoPickerViewController *)picker {
    NSLog(@"%s",__func__);
}

//低于最低选择项时
- (void)photoPickerDidMinimum:(AJPhotoPickerViewController *)picker {
    NSLog(@"%s",__func__);
}

- (void)photoPickerTapCameraAction:(AJPhotoPickerViewController *)picker {
    [self checkCameraAvailability:^(BOOL auth) {
        if (!auth) {
            NSLog(@"没有访问相机权限");
            return;
        }
        [picker dismissViewControllerAnimated:NO completion:nil];
        UIImagePickerController *cameraUI = [UIImagePickerController new];
        cameraUI.allowsEditing = NO;
        cameraUI.delegate = self;
        cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
        cameraUI.cameraFlashMode=UIImagePickerControllerCameraFlashModeAuto;
        
        [self presentViewController: cameraUI animated: YES completion:nil];
    }];
}

#pragma mark - AJPhotoBrowserDelegate


- (void)photoBrowser:(AJPhotoBrowserViewController *)vc deleteWithIndex:(NSInteger)index {
    NSLog(@"%s",__func__);
    
    long i = self.photos.count - 1;
    _imageScrollV.contentSize = CGSizeMake(105 * i - 5, 0);
    i--;
//    if (i) {
//        [_imageScrollV removeFromSuperview];
//    }
    
}

- (void)photoBrowser:(AJPhotoBrowserViewController *)vc didDonePhotos:(NSArray *)photos {
    NSLog(@"%s",__func__);
    [self.photos removeAllObjects];
    [self.photos addObjectsFromArray:photos];
    
        for (UIView *view in _imageScrollV.subviews) {
            [view removeFromSuperview];
        }
        CGFloat x = 0;
        CGRect frame = CGRectMake(0, 0, 100, 100);
        for (int i = 0 ; i < self.photos.count; i++) {
            ALAsset *asset = self.photos[i];
            UIImage *tempImg = [UIImage imageWithCGImage:asset.defaultRepresentation.fullScreenImage];
            frame.origin.x = x;
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            imageView.clipsToBounds = YES;
            imageView.image = tempImg;
            NSData *data = UIImageJPEGRepresentation(tempImg, 0.4);
            NSString* encodeResult = [data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
            if (encodeResult) {
                
                [self.scPhotos addObject:encodeResult];
                //NSLog(@"ppppppic%@",self.photos);
            }else{
                // [self.photos addObject:data];
            }

            imageView.tag = i;
            imageView.userInteractionEnabled = YES;
            [imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showBig:)]];
            [_imageScrollV addSubview:imageView];
            x += frame.size.width+5;
        }
        
        _imageScrollV.contentSize = CGSizeMake(105 * self.photos.count - 5, 0);
    [vc dismissViewControllerAnimated:YES completion:nil];
   // NSLog(@"ppppppic%@",self.photos);
    
}

- (void)showBig:(UITapGestureRecognizer *)sender {
    NSInteger index = sender.view.tag;
    AJPhotoBrowserViewController *photoBrowserViewController = [[AJPhotoBrowserViewController alloc] initWithPhotos:self.photos index:index];
    photoBrowserViewController.delegate = self;
    [self presentViewController:photoBrowserViewController animated:YES completion:nil];}

#pragma mark - UIImagePickerDelegate
- (void)imagePickerControllerDidCancel:(UIImagePickerController *) picker {
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo {
    if (!error) {
        NSLog(@"保存到相册成功");
    }else{
        NSLog(@"保存到相册出错%@", error);
    }
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    UIImage *originalImage;
    if (CFStringCompare((CFStringRef) mediaType,kUTTypeImage, 0)== kCFCompareEqualTo) {
        originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
    }
    //    self.imageView.image = originalImage;
    [self.ceamePhotos addObject:originalImage];
    NSLog(@"%@",self.ceamePhotos);
    CGFloat x = 0;
    CGRect frame = CGRectMake(0, 0, 100, 100);
    if (self.photos.count == 0) {
        for (int i = 0 ; i < self.ceamePhotos.count; i++) {
        frame.origin.x = x;
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
        [imageView setContentMode:UIViewContentModeScaleAspectFill];
        imageView.clipsToBounds = YES;
        imageView.image = self.ceamePhotos[i];
        //        imageView.tag = i;
        imageView.userInteractionEnabled = YES;
        [imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showBig:)]];
        [_imageScrollV addSubview:imageView];
        x += frame.size.width+5;
        }
    }else{
        NSLog(@"%ld",self.ceamePhotos.count);
        for (int i = 0 ; i < self.ceamePhotos.count; i++) {
            frame.origin.x = 105 *(self.photos.count+self.ceamePhotos.count - 1);
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            imageView.clipsToBounds = YES;
            imageView.image = self.ceamePhotos[i];
            //        imageView.tag = i;
            imageView.userInteractionEnabled = YES;
            [imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showBig:)]];
            [_imageScrollV addSubview:imageView];
            x += frame.size.width+5;
        }
    }
    _imageScrollV.contentSize = CGSizeMake(105 * (self.photos.count+self.ceamePhotos.count), 0);
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

- (void)checkCameraAvailability:(void (^)(BOOL auth))block {
    BOOL status = NO;
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if(authStatus == AVAuthorizationStatusAuthorized) {
        status = YES;
    } else if (authStatus == AVAuthorizationStatusDenied) {
        status = NO;
    } else if (authStatus == AVAuthorizationStatusRestricted) {
        status = NO;
    } else if (authStatus == AVAuthorizationStatusNotDetermined) {
        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
            if(granted){
                if (block) {
                    block(granted);
                }
            } else {
                if (block) {
                    block(granted);
                }
            }
        }];
        return;
    }
    if (block) {
        block(status);
    }
}

- (NSMutableArray *)photos {
    if (_photos == nil) {
        _photos = [NSMutableArray array];
    }
    return _photos;
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
